using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WozLib.UI.Controls
{
  /// <summary>
  /// Interaction logic for AlphaSlider.xaml
  /// </summary>

  public partial class AlphaSlider : Slider
  {
    public static readonly DependencyProperty BaseColorProperty =
            DependencyProperty.Register("BaseColor", typeof(Color), typeof(AlphaSlider),
      new UIPropertyMetadata(new PropertyChangedCallback(BaseColor_Changed)));

    public static readonly DependencyProperty InternalBaseColorProperty =
            DependencyProperty.Register("InternalBaseColor", typeof(Color), typeof(AlphaSlider));

    public static readonly DependencyProperty InternalEndColorProperty =
            DependencyProperty.Register("InternalEndColor", typeof(Color), typeof(AlphaSlider));

    private static void BaseColor_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
      if (d is AlphaSlider)
      {
        AlphaSlider alphaSlider = d as AlphaSlider;
        if (e.Property == BaseColorProperty)
        {
          Color c = (Color)e.NewValue;
          alphaSlider.SetValue(InternalBaseColorProperty, Color.FromScRgb((float)alphaSlider.Maximum, c.ScR, c.ScG, c.ScB));
          alphaSlider.SetValue(InternalEndColorProperty, Color.FromScRgb((float)alphaSlider.Minimum, c.ScR, c.ScG, c.ScB));
        }
      }
    }

    public AlphaSlider()
    {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(AlphaSlider_Loaded);
    }

    private void AlphaSlider_Loaded(object sender, RoutedEventArgs e)
    {
    }

    void ColorSlider_MouseDown(object sender, MouseButtonEventArgs e)
    {
      System.Windows.Point point;
      FrameworkElement host;

      host = sender as System.Windows.FrameworkElement;
      point = System.Windows.Input.Mouse.GetPosition(host);

      this.Value = (host.ActualHeight - point.Y) / host.ActualHeight;
    }

  }

}